﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication1
{
    class Clienti
    {
        //un pool de clienti
        private List<Client> lista_clienti;
        
        //clienti de tip singleton
        private static Clienti instantiere = null;

        private Clienti()
        {
            lista_clienti = new List<Client>();
        }

        public static Clienti InstantiereClienti()
        {
            if (instantiere == null)
                instantiere = new Clienti();

            return instantiere;
        }

        private Client existClient(string n, string p, int v)
        {
            if(lista_clienti != null)
                foreach (Client c in lista_clienti)
                {
                    if (c.exista(n, p, v))
                        return c;
                }
            return null;
        }

        public bool addClient(string n, string p, int v)
        {
            Client c;
            c = existClient(n, p, v);
            if (c == null)
            {
                c = new Client(n, p, v);
                lista_clienti.Add(c);
                return true;
            }

            return false;
        }

        public Client getClient(string n, string p, int v)
        {
            return existClient(n, p, v);
        }

        public void rmClient(string n, string p, int v)
        {
            Client c = getClient(n, p, v);
            lista_clienti.Remove(c);
        }

        public string print()
        {
            string s = "NrCrt\tNume\tPrenume\tVarsta\n";
            int i = 1;

            if (lista_clienti != null)
                foreach (Client c in lista_clienti)
                {
                    s += i + "\t" + c.print() + "\n";
                    i++;
                }
            //Console.WriteLine(s);
            return s;
        }
    }
}
